//package com.boot2.core.test.dynamicDataSourc;
//
//import com.boot2.core.dao.datasource.DynamicDataSource;
//import com.boot2.core.utils.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
//import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
//import org.springframework.orm.jpa.JpaTransactionManager;
//import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//
//import javax.persistence.EntityManager;
//import javax.sql.DataSource;
//import java.util.Map;
//
///**
//* @author zhangweilin
//* @date 2019/4/27 11:08
//* @description:  默认的主数据源
//*/
//@Configuration
//@EnableTransactionManagement
//@EnableJpaRepositories(
//        entityManagerFactoryRef = "entityManagerFactoryTest1",
//        transactionManagerRef = "transactionManager",//当配置多数据源时，主数据源中，此name不能变，固定为transactionManager
//        basePackages = {"com.yoju.dao.device", "com.yoju.dao.app", "com.boot2.core.dao", "com.yoju.dao.magicMirror"}) //设置Repository所在位置
////开启的开关为配置此值,即启用了多数据源，才走此配置文件
//@ConditionalOnProperty("spring.datasource.customDefaultName")
//public class DatasourcePrimaryConfig {
//
//    private static final String dataSourceName = "Test1";
//    private static final String dataSourceName0 = StringUtils.changFirstWord(dataSourceName, 1);
//
//    @Autowired
//    private DynamicDataSource dynamicDataSource;
//
//    @Autowired
//    private JpaProperties jpaProperties;
//
//    @Primary
//    @Bean(name = "entityManager"+dataSourceName)
//    public EntityManager entityManager(EntityManagerFactoryBuilder builder) {
//        return entityManagerFactory(builder).getObject().createEntityManager();
//    }
//
//    @Primary
//    @Bean(name = "entityManagerFactory"+dataSourceName)
//    public LocalContainerEntityManagerFactoryBean entityManagerFactory(EntityManagerFactoryBuilder builder) {
//        return builder
//                .dataSource(dynamicDataSource)
//                .properties(getVendorProperties(dynamicDataSource))
//                .packages("com.yoju.model.device","com.yoju.model.app","com.boot2.core.po","com.yoju.model.magicMirror") //设置实体类所在位置
//                .persistenceUnit(dataSourceName0+"PersistenceUnit")
//                .build();
//    }
//
//    private Map getVendorProperties(DataSource dataSource) {
//        return jpaProperties.getHibernateProperties(dataSource);
//    }
//
//    /**
//     * 当配置多数据源时，主数据源中，此name不能变，固定为transactionManager
//     * @param builder
//     * @return
//     */
//    @Primary
//    @Bean(name = "transactionManager")
//    public PlatformTransactionManager transactionManager(EntityManagerFactoryBuilder builder) {
//        return new JpaTransactionManager(entityManagerFactory(builder).getObject());
//    }
//
//}